package com.premedsidekick;

import java.util.Iterator;
import java.util.Map;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class Profile extends Activity {
	ProgressBar overall, school, extra, mcat;
	SharedPreferences preferences;
	int max_overall, max_school, max_extra, max_mcat;
	String school_file, extra_file, mcat_file;
	boolean temp;
	int mcat_counter, course_counter, extra_counter;
	Button reset;
	
	public void onCreate (Bundle bundle) {
		super.onCreate (bundle);
		setContentView (R.layout.profiletest);
		school_file = "courserequirements_file";
		extra_file = "extra_file";
		mcat_file = "mcat_file";
		max_extra = 4;
		max_school = 4;
		max_mcat = 99;
		max_overall = max_extra + max_school + max_mcat;
		
		extra = (ProgressBar) findViewById(R.id.extra_progress_bar);
		preferences = getSharedPreferences (extra_file, 0);
		extra_counter = 0;
		if (preferences.getBoolean("clinic_check", false) == true)
			extra_counter++;
		if (preferences.getBoolean("physician_check", false) == true)
			extra_counter++;
		if (preferences.getBoolean("research_check", false) == true)
			extra_counter++;
		if (preferences.getBoolean("service_check", false) == true)
			extra_counter++;
		extra.setMax(max_extra);
		extra.setProgress(extra_counter);
		
		school = (ProgressBar) findViewById(R.id.school_progress_bar);
		preferences = getSharedPreferences (school_file, 0);
		course_counter = 0;
		if (preferences.getBoolean("biology_check", false) == true) 
			course_counter++;
		if (preferences.getBoolean("chemistry_check", false) == true)
			course_counter++;
		if (preferences.getBoolean("ochem_check", false) == true)
			course_counter++;
		if (preferences.getBoolean("physics_check", false) == true)
			course_counter++;
		school.setMax(max_school);
		school.setProgress(course_counter);

		Map<String,?> container;
		preferences = getSharedPreferences (mcat_file, 0);
		container = preferences.getAll();
		//container.values().iterator();
		
		/*
		for (int i = 0; i < container.size(); i++) {
			if (true) {}	
		}
		*/
		mcat_counter = 0;
		Iterator it = container.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry pairs = (Map.Entry)it.next();
			if ((Boolean)pairs.getValue() == true) {
				//System.out.println(pairs.getKey());
				mcat_counter++;
			}
		}
		mcat = (ProgressBar) findViewById(R.id.mcat_progress_bar);
		mcat.setMax(max_mcat);
		//System.out.println("Overall: " + mcat_counter);
		mcat.setProgress(mcat_counter);
		/*
		for (Map.Entry<String, String> entry : map.entrySet())
		{
		    System.out.println(entry.getKey() + "/" + entry.getValue());
		}
		*/
		overall = (ProgressBar) findViewById(R.id.overall_progress_bar);
		overall.setMax(max_overall);
		overall.setProgress (mcat_counter + course_counter + extra_counter);
		
		reset = (Button) findViewById(R.id.reseter);
		reset.setOnClickListener(new OnClickListener () {
			public void onClick (View view) {
				/*
				 	school_file = "courserequirements_file";
					extra_file = "extra_file";
					mcat_file = "mcat_file";
				 */
				SharedPreferences preferences = getSharedPreferences (school_file, 0);
				SharedPreferences.Editor editor = preferences.edit();
				editor.clear();
				editor.commit();
				preferences = getSharedPreferences (extra_file, 0);
				editor = preferences.edit();
				editor.clear();
				editor.commit();
				preferences = getSharedPreferences (mcat_file, 0);
				editor = preferences.edit();
				editor.clear();
				editor.commit();
			}
		});
	}
}
